﻿using S.Authorization.Domain.Model.Authority;
using S.Authorization.Domain.Model.Organization;
using S.Authorization.Domain.SqlServer;
using S.Authorization.Infrastructure.Interface.Organization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace S.Authorization.Infrastructure.Impl.Organization
{
    public class FieldModelRepository : BaseRepository<FieldModel>, IFieldModelRepository
    {
        public FieldModelRepository(SqlDbContext db) : base(db)
        {
        }

        public async Task<int> AddRangeFieldModelAsync(List<FieldModel> models)
        {
            var tran = db.Database.BeginTransaction();
            int isOk = 0;
            try
            {
                //先查询
                //int[] ids = models.Select(x => x.ColumnManagementId).ToArray();
                //List<FieldModel> featureRoleMenuList = db.FieldModel.Where(x => ids.Contains(x.ColumnManagementId)).ToList();
                //批量添加
                db.FieldModel.AddRangeAsync(models);
                isOk += await db.SaveChangesAsync();
                tran.CommitAsync();
                return isOk;
            }
            catch (Exception)
            {
                tran.RollbackAsync();
                throw;
            }
        }
    }
}
